package com.cheer.controller;

import com.cheer.common.Result;
import com.cheer.dto.MallComplaintAddDTO;
import com.cheer.entity.MallComplaintEntity;
import com.cheer.service.AuthService;
import com.cheer.service.MallComplaintService;
import com.cheer.vo.MallComplaintListVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import javax.validation.Valid;
import java.util.List;

/**
 * @author cheer
 */
@RestController
@RequestMapping("/complaint")
public class MallComplaintController {

    @Autowired
    private MallComplaintService mallComplaintService;

    @Autowired
    private AuthService authService;

    @ApiOperation("提交投诉")
    @PostMapping("/add")
    public Result add(@RequestBody @Valid MallComplaintAddDTO complaintAddDTO, HttpSession session) {
        mallComplaintService.add(complaintAddDTO, authService.getUserId(session));
        return Result.success();
    }

    @ApiOperation("查看用户的投诉列表")
    @GetMapping("/list")
    public Result<List<MallComplaintListVO>> list(HttpSession session){
        return Result.success(mallComplaintService.listByUserId(authService.getUserId(session)));
    }

    @ApiOperation("查看投诉")
    @GetMapping("/info")
    public Result<MallComplaintListVO> info(Long id,
                                            HttpSession session){
        authService.getUserId(session);
        return Result.success(mallComplaintService.info(id));
    }
}
